#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const int A = 1e6 + 5;
int n, m;
int a[N];
int pos[A];
ll cnt[N];
ll dp[N];

void solve() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  cnt[1] = 0;
  rep(i, 2, n) cnt[i] = cnt[i - 1] + (a[i] == a[i - 1] ? a[i] : 0);
  memset(pos, 0, sizeof(pos));
  dp[0] = 0;
  rep(i, 1, n) {
    int pre = pos[a[i]];
    pos[a[i]] = i;
    dp[i] = dp[i - 1];
    if (pre) {
      if (pre == i - 1)
        dp[i] = max(dp[i], dp[pre] + a[i]);  // pre == 0
      else
        dp[i] = max(dp[i], dp[pre + 1] + (cnt[i - 1] - cnt[pre]) + a[i]);
    }
  }
  cout << dp[n] << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}